﻿using System;
using HslCommunication.Core.Net;
using HslCommunication.ModBus;
using HslCommunication.Profinet.AllenBradley;
using HslCommunication.Profinet.Melsec;
using HslCommunication.Profinet.Omron;
using HslCommunication.Profinet.Siemens;
using Newtonsoft.Json.Linq;

namespace HslCommunication.DTU
{
	/// <summary>
	/// DTU的类型设置器
	/// </summary>
	// Token: 0x02000109 RID: 265
	public class DTUSettingType
	{
		/// <summary>
		/// 设备的唯一ID信息
		/// </summary>
		// Token: 0x1700050A RID: 1290
		// (get) Token: 0x06001789 RID: 6025 RVA: 0x00077E73 File Offset: 0x00076073
		// (set) Token: 0x0600178A RID: 6026 RVA: 0x00077E7B File Offset: 0x0007607B
		public string DtuId { get; set; }

		/// <summary>
		/// 当前的设备的类型
		/// </summary>
		// Token: 0x1700050B RID: 1291
		// (get) Token: 0x0600178B RID: 6027 RVA: 0x00077E84 File Offset: 0x00076084
		// (set) Token: 0x0600178C RID: 6028 RVA: 0x00077E8C File Offset: 0x0007608C
		public string DtuType { get; set; } = "ModbusRtuOverTcp";

		/// <summary>
		/// 额外的参数都存放在json里面
		/// </summary>
		// Token: 0x1700050C RID: 1292
		// (get) Token: 0x0600178D RID: 6029 RVA: 0x00077E95 File Offset: 0x00076095
		// (set) Token: 0x0600178E RID: 6030 RVA: 0x00077E9D File Offset: 0x0007609D
		public string JsonParameter { get; set; } = "{}";

		/// <summary>
		/// 根据类型，获取连接对象
		/// </summary>
		/// <returns>获取设备的连接对象</returns>
		// Token: 0x0600178F RID: 6031 RVA: 0x00077EA8 File Offset: 0x000760A8
		public virtual NetworkDeviceBase GetClient()
		{
			JObject jobject = JObject.Parse(this.JsonParameter);
			bool flag = this.DtuType == "ModbusRtuOverTcp";
			NetworkDeviceBase result;
			if (flag)
			{
				result = new ModbusRtuOverTcp("127.0.0.1", 502, Extensions.Value<byte>(jobject["Station"]))
				{
					ConnectionId = this.DtuId
				};
			}
			else
			{
				bool flag2 = this.DtuType == "ModbusTcpNet";
				if (flag2)
				{
					result = new ModbusTcpNet("127.0.0.1", 502, Extensions.Value<byte>(jobject["Station"]))
					{
						ConnectionId = this.DtuId
					};
				}
				else
				{
					bool flag3 = this.DtuType == "MelsecMcNet";
					if (flag3)
					{
						result = new MelsecMcNet("127.0.0.1", 5000)
						{
							ConnectionId = this.DtuId
						};
					}
					else
					{
						bool flag4 = this.DtuType == "MelsecMcAsciiNet";
						if (flag4)
						{
							result = new MelsecMcAsciiNet("127.0.0.1", 5000)
							{
								ConnectionId = this.DtuId
							};
						}
						else
						{
							bool flag5 = this.DtuType == "MelsecA1ENet";
							if (flag5)
							{
								result = new MelsecA1ENet("127.0.0.1", 5000)
								{
									ConnectionId = this.DtuId
								};
							}
							else
							{
								bool flag6 = this.DtuType == "MelsecA1EAsciiNet";
								if (flag6)
								{
									result = new MelsecA1EAsciiNet("127.0.0.1", 5000)
									{
										ConnectionId = this.DtuId
									};
								}
								else
								{
									bool flag7 = this.DtuType == "MelsecA3CNet1OverTcp";
									if (flag7)
									{
										result = new MelsecA3CNet1OverTcp("127.0.0.1", 5000)
										{
											ConnectionId = this.DtuId
										};
									}
									else
									{
										bool flag8 = this.DtuType == "MelsecFxLinksOverTcp";
										if (flag8)
										{
											result = new MelsecFxLinksOverTcp("127.0.0.1", 5000)
											{
												ConnectionId = this.DtuId
											};
										}
										else
										{
											bool flag9 = this.DtuType == "MelsecFxSerialOverTcp";
											if (flag9)
											{
												result = new MelsecFxSerialOverTcp("127.0.0.1", 5000)
												{
													ConnectionId = this.DtuId
												};
											}
											else
											{
												bool flag10 = this.DtuType == "SiemensS7Net";
												if (flag10)
												{
													result = new SiemensS7Net((SiemensPLCS)Enum.Parse(typeof(SiemensPLCS), Extensions.Value<string>(jobject["SiemensPLCS"])))
													{
														ConnectionId = this.DtuId
													};
												}
												else
												{
													bool flag11 = this.DtuType == "SiemensFetchWriteNet";
													if (flag11)
													{
														result = new SiemensFetchWriteNet("127.0.0.1", 5000)
														{
															ConnectionId = this.DtuId
														};
													}
													else
													{
														bool flag12 = this.DtuType == "SiemensPPIOverTcp";
														if (flag12)
														{
															result = new SiemensPPIOverTcp("127.0.0.1", 5000)
															{
																ConnectionId = this.DtuId
															};
														}
														else
														{
															bool flag13 = this.DtuType == "OmronFinsNet";
															if (flag13)
															{
																result = new OmronFinsNet("127.0.0.1", 5000)
																{
																	ConnectionId = this.DtuId
																};
															}
															else
															{
																bool flag14 = this.DtuType == "OmronHostLinkOverTcp";
																if (flag14)
																{
																	result = new OmronHostLinkOverTcp("127.0.0.1", 5000)
																	{
																		ConnectionId = this.DtuId
																	};
																}
																else
																{
																	bool flag15 = this.DtuType == "AllenBradleyNet";
																	if (!flag15)
																	{
																		throw new NotImplementedException();
																	}
																	result = new AllenBradleyNet("127.0.0.1", 5000)
																	{
																		ConnectionId = this.DtuId
																	};
																}
															}
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
			return result;
		}
	}
}
